<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <title>用户管理</title>
  <link href="${ctx}/static/support/icheck-1.0.2/skins/all.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
  <!-- 路径导航 -->
  <ol class="breadcrumb">
    <li><a href="${ctx}/workbench">主页</a></li>
    <li><a href="${ctx}/user">用户管理</a></li>
    <li class="active">
      <c:if test="${action eq 'create'}">添加用户</c:if>
      <c:if test="${action eq 'update'}">修改用户</c:if>
    </li>
  </ol>
  <!-- /路径导航 -->

  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">
        <c:if test="${action eq 'create'}">添加用户</c:if>
        <c:if test="${action eq 'update'}">修改用户</c:if>
      </h3>
    </div>

    <div class="panel-body">
      <form class="form-horizontal" id="user-form" action="${ctx}/user/${action}" method="post" role="form">
        <input type="hidden" id="user-id" name="id" value="${user.id}">

        <div class="form-group">
          <label for="user-name" class="col-sm-2 control-label">登录账号</label>

          <div class="col-sm-10">
            <input type="text" class="form-control" id="user-login-name" name="loginName" value="${user.loginName}"
                   <c:if test="${user.id ne null}">readonly="readonly"</c:if> placeholder="登录账号">
          </div>
        </div>

        <div class="form-group">
          <label for="user-name" class="col-sm-2 control-label">姓名</label>

          <div class="col-sm-10">
            <input type="text" class="form-control" id="user-name" name="name" value="${user.name}" placeholder="姓名">
          </div>
        </div>

        <div class="form-group">
          <label for="user-name" class="col-sm-2 control-label">邮箱地址</label>

          <div class="col-sm-10">
            <input type="text" class="form-control" id="user-email" name="email" value="${user.email}" placeholder="邮箱地址">
          </div>
        </div>

        <div class="form-group">
          <label for="user-name" class="col-sm-2 control-label">创建密码</label>

          <div class="col-sm-10">
            <input type="text" class="form-control" id="user-plain-password" name="plainPassword" value="${user.plainPassword}" placeholder="创建密码">
          </div>
        </div>

        <div class="form-group">
          <label for="user-name" class="col-sm-2 control-label">确认密码</label>

          <div class="col-sm-10">
            <input type="text" class="form-control" id="user-confirm-password" name="confirmPassword" placeholder="确认密码">
          </div>
        </div>

        <c:if test="${user.id ne null}">
          <div class="form-group">
            <label for="user-name" class="col-sm-2 control-label">注册日期</label>

            <div class="col-sm-10">
              <p class="form-control-static">
                <fmt:formatDate value="${user.registerDate}" pattern="yyyy年MM月dd日  HH时mm分ss秒"/>
              </p>
            </div>
          </div>
        </c:if>

        <div class="form-group">
          <label for="user-name" class="col-sm-2 control-label">角色</label>

          <div class="col-sm-10">
            <c:forEach items="${allRole }" var="role" varStatus="status">
              <label class="checkbox-inline" style="padding-left: 0px;">
                <input type="checkbox" name="roles.id" value="${role.id}" <c:if test="${isExist[role.id]}">checked="checked"</c:if>>
                  <span style="margin-left: 0px; vertical-align: middle;">${role.name}</span>
              </label>
            </c:forEach>
          </div>
        </div>

        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default" onclick="return confirm('是否提交上面的信息？')"> 提 交</button>
            <button type="button" class="btn btn-default" onclick="history.back()"> 返 回</button>
          </div>
        </div>
      </form>
    </div>

  </div>

</div>

<!-- 以下开始 加载JS动态效果 -->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="${ctx}/static/jquery/jquery-1.11.3.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="${ctx}/static/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>

<!-- 增强复选框和单选框 -->
<script src="${ctx}/static/support/icheck-1.0.2/icheck.min.js"></script>

<script type="text/javascript">
  jQuery(document).ready(function () {
    $(':checkbox').iCheck({
      checkboxClass: 'icheckbox_minimal'
    });
  });
</script>

</body>
</html>